{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PyEcharts天猫数据可视化项目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 订单数据分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "本数据集共收集了发生在一个月内的28010条数据，包含以下：\n",
    "- 订单编号\n",
    "- 总金额\n",
    "- 买家实际支付金额: 总金额-退款金额\n",
    "- 收货地址： 各个省份\n",
    "- 订单创建时间\n",
    "- 订单付款时间\n",
    "- 退款金额： 付款后申请退款的金额。如无付过款，退款金额为0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map, Timeline, Bar, Line, Pie"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "      <th>总金额</th>\n",
       "      <th>买家实际支付金额</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>订单创建时间</th>\n",
       "      <th>订单付款时间</th>\n",
       "      <th>退款金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>178.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>2022-03-21 00:00:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>内蒙古自治区</td>\n",
       "      <td>2022-03-20 23:59:54</td>\n",
       "      <td>2022-03-21 00:00:02</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>2022-03-20 23:59:35</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>157.0</td>\n",
       "      <td>157.0</td>\n",
       "      <td>湖南省</td>\n",
       "      <td>2022-03-20 23:58:34</td>\n",
       "      <td>2022-03-20 23:58:44</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>64.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>2022-03-20 23:57:04</td>\n",
       "      <td>2022-03-20 23:57:11</td>\n",
       "      <td>64.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单编号    总金额  买家实际支付金额   收货地址                订单创建时间              订单付款时间   \\\n",
       "0     1  178.8       0.0      上海  2022-03-21 00:00:00                  NaN   \n",
       "1     2   21.0      21.0  内蒙古自治区  2022-03-20 23:59:54  2022-03-21 00:00:02   \n",
       "2     3   37.0       0.0     安徽省  2022-03-20 23:59:35                  NaN   \n",
       "3     4  157.0     157.0     湖南省  2022-03-20 23:58:34  2022-03-20 23:58:44   \n",
       "4     5   64.8       0.0     江苏省  2022-03-20 23:57:04  2022-03-20 23:57:11   \n",
       "\n",
       "   退款金额  \n",
       "0   0.0  \n",
       "1   0.0  \n",
       "2   0.0  \n",
       "3   0.0  \n",
       "4  64.8  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('tmall_order_report.csv')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(28010, 7)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape\n",
    "\n",
    "# 28010行 7列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 28010 entries, 0 to 28009\n",
      "Data columns (total 7 columns):\n",
      " #   Column    Non-Null Count  Dtype  \n",
      "---  ------    --------------  -----  \n",
      " 0   订单编号      28010 non-null  int64  \n",
      " 1   总金额       28010 non-null  float64\n",
      " 2   买家实际支付金额  28010 non-null  float64\n",
      " 3   收货地址      28010 non-null  object \n",
      " 4   订单创建时间    28010 non-null  object \n",
      " 5   订单付款时间    24087 non-null  object \n",
      " 6   退款金额      28010 non-null  float64\n",
      "dtypes: float64(3), int64(1), object(3)\n",
      "memory usage: 1.5+ MB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['订单编号', '总金额', '买家实际支付金额', '收货地址 ', '订单创建时间', '订单付款时间 ', '退款金额'], dtype='object')"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 去除列名中的空格\n",
    "data.columns = data.columns.str.strip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['订单编号', '总金额', '买家实际支付金额', '收货地址', '订单创建时间', '订单付款时间', '退款金额'], dtype='object')"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 重复值查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.duplicated().sum()\n",
    "\n",
    "# 没有重复值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 缺失值查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "订单编号           0\n",
       "总金额            0\n",
       "买家实际支付金额       0\n",
       "收货地址           0\n",
       "订单创建时间         0\n",
       "订单付款时间      3923\n",
       "退款金额           0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# data.info()\n",
    "\n",
    "data.isnull().sum()\n",
    "#  订单付款时间   有3923空"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PyEcharts数据可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "      <th>总金额</th>\n",
       "      <th>买家实际支付金额</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>订单创建时间</th>\n",
       "      <th>订单付款时间</th>\n",
       "      <th>退款金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>178.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>2022-03-21 00:00:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>内蒙古自治区</td>\n",
       "      <td>2022-03-20 23:59:54</td>\n",
       "      <td>2022-03-21 00:00:02</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>2022-03-20 23:59:35</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>157.0</td>\n",
       "      <td>157.0</td>\n",
       "      <td>湖南省</td>\n",
       "      <td>2022-03-20 23:58:34</td>\n",
       "      <td>2022-03-20 23:58:44</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>64.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>2022-03-20 23:57:04</td>\n",
       "      <td>2022-03-20 23:57:11</td>\n",
       "      <td>64.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单编号    总金额  买家实际支付金额    收货地址               订单创建时间               订单付款时间  \\\n",
       "0     1  178.8       0.0      上海  2022-03-21 00:00:00                  NaN   \n",
       "1     2   21.0      21.0  内蒙古自治区  2022-03-20 23:59:54  2022-03-21 00:00:02   \n",
       "2     3   37.0       0.0     安徽省  2022-03-20 23:59:35                  NaN   \n",
       "3     4  157.0     157.0     湖南省  2022-03-20 23:58:34  2022-03-20 23:58:44   \n",
       "4     5   64.8       0.0     江苏省  2022-03-20 23:57:04  2022-03-20 23:57:11   \n",
       "\n",
       "   退款金额  \n",
       "0   0.0  \n",
       "1   0.0  \n",
       "2   0.0  \n",
       "3   0.0  \n",
       "4  64.8  "
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 各省份的订单量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "上海          3353\n",
       "广东省         2463\n",
       "江苏省         2126\n",
       "浙江省         2061\n",
       "北京          2054\n",
       "四川省         2019\n",
       "山东省         1804\n",
       "辽宁省         1187\n",
       "天津          1153\n",
       "湖南省         1099\n",
       "河北省         1083\n",
       "重庆          1036\n",
       "河南省          966\n",
       "云南省          778\n",
       "安徽省          609\n",
       "陕西省          536\n",
       "福建省          489\n",
       "山西省          465\n",
       "广西壮族自治区      436\n",
       "江西省          411\n",
       "吉林省          401\n",
       "黑龙江省         379\n",
       "贵州省          345\n",
       "内蒙古自治区       215\n",
       "海南省          178\n",
       "甘肃省          167\n",
       "湖北省           75\n",
       "新疆维吾尔自治区      58\n",
       "宁夏回族自治区       42\n",
       "青海省           19\n",
       "西藏自治区          3\n",
       "Name: 收货地址, dtype: int64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.收货地址.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "def province_map(p):\n",
    "    if p in ['北京', '天津', '上海', '重庆']:\n",
    "        return p + '市'\n",
    "    return p\n",
    "\n",
    "data.收货地址 = data.收货地址.map(province_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "上海市         3353\n",
       "广东省         2463\n",
       "江苏省         2126\n",
       "浙江省         2061\n",
       "北京市         2054\n",
       "四川省         2019\n",
       "山东省         1804\n",
       "辽宁省         1187\n",
       "天津市         1153\n",
       "湖南省         1099\n",
       "河北省         1083\n",
       "重庆市         1036\n",
       "河南省          966\n",
       "云南省          778\n",
       "安徽省          609\n",
       "陕西省          536\n",
       "福建省          489\n",
       "山西省          465\n",
       "广西壮族自治区      436\n",
       "江西省          411\n",
       "吉林省          401\n",
       "黑龙江省         379\n",
       "贵州省          345\n",
       "内蒙古自治区       215\n",
       "海南省          178\n",
       "甘肃省          167\n",
       "湖北省           75\n",
       "新疆维吾尔自治区      58\n",
       "宁夏回族自治区       42\n",
       "青海省           19\n",
       "西藏自治区          3\n",
       "Name: 收货地址, dtype: int64"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.收货地址.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "      <th>总金额</th>\n",
       "      <th>买家实际支付金额</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>订单创建时间</th>\n",
       "      <th>订单付款时间</th>\n",
       "      <th>退款金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>内蒙古自治区</td>\n",
       "      <td>2022-03-20 23:59:54</td>\n",
       "      <td>2022-03-21 00:00:02</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>157.0</td>\n",
       "      <td>157.0</td>\n",
       "      <td>湖南省</td>\n",
       "      <td>2022-03-20 23:58:34</td>\n",
       "      <td>2022-03-20 23:58:44</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>64.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>2022-03-20 23:57:04</td>\n",
       "      <td>2022-03-20 23:57:11</td>\n",
       "      <td>64.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>327.7</td>\n",
       "      <td>148.9</td>\n",
       "      <td>浙江省</td>\n",
       "      <td>2022-03-20 23:56:39</td>\n",
       "      <td>2022-03-20 23:56:53</td>\n",
       "      <td>178.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>357.0</td>\n",
       "      <td>357.0</td>\n",
       "      <td>天津市</td>\n",
       "      <td>2022-03-20 23:56:36</td>\n",
       "      <td>2022-03-20 23:56:40</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28002</th>\n",
       "      <td>28003</td>\n",
       "      <td>77.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>重庆市</td>\n",
       "      <td>2022-03-27 00:02:39</td>\n",
       "      <td>2022-03-27 00:03:27</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28003</th>\n",
       "      <td>28004</td>\n",
       "      <td>157.0</td>\n",
       "      <td>157.0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>2022-03-27 00:01:42</td>\n",
       "      <td>2022-03-27 00:01:47</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28005</th>\n",
       "      <td>28006</td>\n",
       "      <td>37.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>四川省</td>\n",
       "      <td>2022-03-27 00:01:00</td>\n",
       "      <td>2022-03-27 00:01:10</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28008</th>\n",
       "      <td>28009</td>\n",
       "      <td>37.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>辽宁省</td>\n",
       "      <td>2022-03-27 00:00:09</td>\n",
       "      <td>2022-03-27 00:00:17</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28009</th>\n",
       "      <td>28010</td>\n",
       "      <td>37.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>广东省</td>\n",
       "      <td>2022-03-27 00:00:06</td>\n",
       "      <td>2022-03-27 00:00:11</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>24087 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        订单编号    总金额  买家实际支付金额    收货地址               订单创建时间  \\\n",
       "1          2   21.0      21.0  内蒙古自治区  2022-03-20 23:59:54   \n",
       "3          4  157.0     157.0     湖南省  2022-03-20 23:58:34   \n",
       "4          5   64.8       0.0     江苏省  2022-03-20 23:57:04   \n",
       "5          6  327.7     148.9     浙江省  2022-03-20 23:56:39   \n",
       "6          7  357.0     357.0     天津市  2022-03-20 23:56:36   \n",
       "...      ...    ...       ...     ...                  ...   \n",
       "28002  28003   77.0      77.0     重庆市  2022-03-27 00:02:39   \n",
       "28003  28004  157.0     157.0     山东省  2022-03-27 00:01:42   \n",
       "28005  28006   37.0      37.0     四川省  2022-03-27 00:01:00   \n",
       "28008  28009   37.0      37.0     辽宁省  2022-03-27 00:00:09   \n",
       "28009  28010   37.0      37.0     广东省  2022-03-27 00:00:06   \n",
       "\n",
       "                    订单付款时间   退款金额  \n",
       "1      2022-03-21 00:00:02    0.0  \n",
       "3      2022-03-20 23:58:44    0.0  \n",
       "4      2022-03-20 23:57:11   64.8  \n",
       "5      2022-03-20 23:56:53  178.8  \n",
       "6      2022-03-20 23:56:40    0.0  \n",
       "...                    ...    ...  \n",
       "28002  2022-03-27 00:03:27    0.0  \n",
       "28003  2022-03-27 00:01:47    0.0  \n",
       "28005  2022-03-27 00:01:10    0.0  \n",
       "28008  2022-03-27 00:00:17    0.0  \n",
       "28009  2022-03-27 00:00:11    0.0  \n",
       "\n",
       "[24087 rows x 7 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看订单付款时间不为空的\n",
    "data.订单付款时间.notnull()\n",
    "\n",
    "# 过滤掉（删掉）没有付款的订单数据\n",
    "data[data.订单付款时间.notnull()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>收货地址</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>上海市</th>\n",
       "      <td>3060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南省</th>\n",
       "      <td>667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙古自治区</th>\n",
       "      <td>176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>北京市</th>\n",
       "      <td>1853</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林省</th>\n",
       "      <td>336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川省</th>\n",
       "      <td>1752</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津市</th>\n",
       "      <td>1031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏回族自治区</th>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽省</th>\n",
       "      <td>528</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东省</th>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西省</th>\n",
       "      <td>395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东省</th>\n",
       "      <td>2022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西壮族自治区</th>\n",
       "      <td>353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆维吾尔自治区</th>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏省</th>\n",
       "      <td>1845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西省</th>\n",
       "      <td>331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北省</th>\n",
       "      <td>885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南省</th>\n",
       "      <td>792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江省</th>\n",
       "      <td>1822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南省</th>\n",
       "      <td>156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北省</th>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南省</th>\n",
       "      <td>935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃省</th>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建省</th>\n",
       "      <td>425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏自治区</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州省</th>\n",
       "      <td>286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁省</th>\n",
       "      <td>1012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆市</th>\n",
       "      <td>896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西省</th>\n",
       "      <td>441</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青海省</th>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江省</th>\n",
       "      <td>312</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          订单编号\n",
       "收货地址          \n",
       "上海市       3060\n",
       "云南省        667\n",
       "内蒙古自治区     176\n",
       "北京市       1853\n",
       "吉林省        336\n",
       "四川省       1752\n",
       "天津市       1031\n",
       "宁夏回族自治区     40\n",
       "安徽省        528\n",
       "山东省       1484\n",
       "山西省        395\n",
       "广东省       2022\n",
       "广西壮族自治区    353\n",
       "新疆维吾尔自治区    43\n",
       "江苏省       1845\n",
       "江西省        331\n",
       "河北省        885\n",
       "河南省        792\n",
       "浙江省       1822\n",
       "海南省        156\n",
       "湖北省         57\n",
       "湖南省        935\n",
       "甘肃省        132\n",
       "福建省        425\n",
       "西藏自治区        2\n",
       "贵州省        286\n",
       "辽宁省       1012\n",
       "重庆市        896\n",
       "陕西省        441\n",
       "青海省         18\n",
       "黑龙江省       312"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计各个省份的订单量\n",
    "\n",
    "result = data[data.订单付款时间.notnull()].groupby('收货地址')[['订单编号']].count()\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'上海市': 3060,\n",
       " '云南省': 667,\n",
       " '内蒙古自治区': 176,\n",
       " '北京市': 1853,\n",
       " '吉林省': 336,\n",
       " '四川省': 1752,\n",
       " '天津市': 1031,\n",
       " '宁夏回族自治区': 40,\n",
       " '安徽省': 528,\n",
       " '山东省': 1484,\n",
       " '山西省': 395,\n",
       " '广东省': 2022,\n",
       " '广西壮族自治区': 353,\n",
       " '新疆维吾尔自治区': 43,\n",
       " '江苏省': 1845,\n",
       " '江西省': 331,\n",
       " '河北省': 885,\n",
       " '河南省': 792,\n",
       " '浙江省': 1822,\n",
       " '海南省': 156,\n",
       " '湖北省': 57,\n",
       " '湖南省': 935,\n",
       " '甘肃省': 132,\n",
       " '福建省': 425,\n",
       " '西藏自治区': 2,\n",
       " '贵州省': 286,\n",
       " '辽宁省': 1012,\n",
       " '重庆市': 896,\n",
       " '陕西省': 441,\n",
       " '青海省': 18,\n",
       " '黑龙江省': 312}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result2 = result.to_dict()['订单编号']\n",
    "result2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_items([('上海市', 3060), ('云南省', 667), ('内蒙古自治区', 176), ('北京市', 1853), ('吉林省', 336), ('四川省', 1752), ('天津市', 1031), ('宁夏回族自治区', 40), ('安徽省', 528), ('山东省', 1484), ('山西省', 395), ('广东省', 2022), ('广西壮族自治区', 353), ('新疆维吾尔自治区', 43), ('江苏省', 1845), ('江西省', 331), ('河北省', 885), ('河南省', 792), ('浙江省', 1822), ('海南省', 156), ('湖北省', 57), ('湖南省', 935), ('甘肃省', 132), ('福建省', 425), ('西藏自治区', 2), ('贵州省', 286), ('辽宁省', 1012), ('重庆市', 896), ('陕西省', 441), ('青海省', 18), ('黑龙江省', 312)])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result2.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('上海市', 3060),\n",
       " ('云南省', 667),\n",
       " ('内蒙古自治区', 176),\n",
       " ('北京市', 1853),\n",
       " ('吉林省', 336),\n",
       " ('四川省', 1752),\n",
       " ('天津市', 1031),\n",
       " ('宁夏回族自治区', 40),\n",
       " ('安徽省', 528),\n",
       " ('山东省', 1484),\n",
       " ('山西省', 395),\n",
       " ('广东省', 2022),\n",
       " ('广西壮族自治区', 353),\n",
       " ('新疆维吾尔自治区', 43),\n",
       " ('江苏省', 1845),\n",
       " ('江西省', 331),\n",
       " ('河北省', 885),\n",
       " ('河南省', 792),\n",
       " ('浙江省', 1822),\n",
       " ('海南省', 156),\n",
       " ('湖北省', 57),\n",
       " ('湖南省', 935),\n",
       " ('甘肃省', 132),\n",
       " ('福建省', 425),\n",
       " ('西藏自治区', 2),\n",
       " ('贵州省', 286),\n",
       " ('辽宁省', 1012),\n",
       " ('重庆市', 896),\n",
       " ('陕西省', 441),\n",
       " ('青海省', 18),\n",
       " ('黑龙江省', 312)]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(result2.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('上海市', 3060),\n",
       " ('云南省', 667),\n",
       " ('内蒙古自治区', 176),\n",
       " ('北京市', 1853),\n",
       " ('吉林省', 336),\n",
       " ('四川省', 1752),\n",
       " ('天津市', 1031),\n",
       " ('宁夏回族自治区', 40),\n",
       " ('安徽省', 528),\n",
       " ('山东省', 1484),\n",
       " ('山西省', 395),\n",
       " ('广东省', 2022),\n",
       " ('广西壮族自治区', 353),\n",
       " ('新疆维吾尔自治区', 43),\n",
       " ('江苏省', 1845),\n",
       " ('江西省', 331),\n",
       " ('河北省', 885),\n",
       " ('河南省', 792),\n",
       " ('浙江省', 1822),\n",
       " ('海南省', 156),\n",
       " ('湖北省', 57),\n",
       " ('湖南省', 935),\n",
       " ('甘肃省', 132),\n",
       " ('福建省', 425),\n",
       " ('西藏自治区', 2),\n",
       " ('贵州省', 286),\n",
       " ('辽宁省', 1012),\n",
       " ('重庆市', 896),\n",
       " ('陕西省', 441),\n",
       " ('青海省', 18),\n",
       " ('黑龙江省', 312)]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[*result2.items()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"4f9ac1751b3b47d691946c280067d332\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_4f9ac1751b3b47d691946c280067d332 = echarts.init(\n",
       "                    document.getElementById('4f9ac1751b3b47d691946c280067d332'), 'white', {renderer: 'canvas'});\n",
       "                var option_4f9ac1751b3b47d691946c280067d332 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5404\\u7701\\u4efd\\u8ba2\\u5355\\u91cf\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\\u5e02\",\n",
       "                    \"value\": 3060\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\\u7701\",\n",
       "                    \"value\": 667\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\\u53e4\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 176\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\\u5e02\",\n",
       "                    \"value\": 1853\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\\u7701\",\n",
       "                    \"value\": 336\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\\u7701\",\n",
       "                    \"value\": 1752\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\\u5e02\",\n",
       "                    \"value\": 1031\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u590f\\u56de\\u65cf\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 40\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\\u7701\",\n",
       "                    \"value\": 528\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\\u7701\",\n",
       "                    \"value\": 1484\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\\u7701\",\n",
       "                    \"value\": 395\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\\u7701\",\n",
       "                    \"value\": 2022\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\\u58ee\\u65cf\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 353\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u7586\\u7ef4\\u543e\\u5c14\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 43\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\\u7701\",\n",
       "                    \"value\": 1845\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\\u7701\",\n",
       "                    \"value\": 331\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\\u7701\",\n",
       "                    \"value\": 885\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\\u7701\",\n",
       "                    \"value\": 792\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\\u7701\",\n",
       "                    \"value\": 1822\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\\u7701\",\n",
       "                    \"value\": 156\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\\u7701\",\n",
       "                    \"value\": 57\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\\u7701\",\n",
       "                    \"value\": 935\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7518\\u8083\\u7701\",\n",
       "                    \"value\": 132\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\\u7701\",\n",
       "                    \"value\": 425\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\\u7701\",\n",
       "                    \"value\": 286\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\\u7701\",\n",
       "                    \"value\": 1012\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\\u5e02\",\n",
       "                    \"value\": 896\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\\u7701\",\n",
       "                    \"value\": 441\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d77\\u7701\",\n",
       "                    \"value\": 18\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\\u7701\",\n",
       "                    \"value\": 312\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": false,\n",
       "            \"emphasis\": {},\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5404\\u7701\\u4efd\\u8ba2\\u5355\\u91cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5404\\u7701\\u4efd\\u8ba2\\u5355\\u91cf\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u5404\\u7701\\u4efd\\u8ba2\\u5355\\u91cf\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 2000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 140,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_4f9ac1751b3b47d691946c280067d332.setOption(option_4f9ac1751b3b47d691946c280067d332);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1e1244cc1c0>"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Map()\n",
    "    .add('各省份订单量', \n",
    "        [*result2.items()], \n",
    "         'china',\n",
    "         is_map_symbol_show=False\n",
    "    )\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(is_show=True))\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='各省份订单量'),\n",
    "        visualmap_opts=opts.VisualMapOpts(max_=2000)\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 时间序列分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "      <th>总金额</th>\n",
       "      <th>买家实际支付金额</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>订单创建时间</th>\n",
       "      <th>订单付款时间</th>\n",
       "      <th>退款金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>178.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>上海市</td>\n",
       "      <td>2022-03-21 00:00:00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>内蒙古自治区</td>\n",
       "      <td>2022-03-20 23:59:54</td>\n",
       "      <td>2022-03-21 00:00:02</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>2022-03-20 23:59:35</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>157.0</td>\n",
       "      <td>157.0</td>\n",
       "      <td>湖南省</td>\n",
       "      <td>2022-03-20 23:58:34</td>\n",
       "      <td>2022-03-20 23:58:44</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>64.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>2022-03-20 23:57:04</td>\n",
       "      <td>2022-03-20 23:57:11</td>\n",
       "      <td>64.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单编号    总金额  买家实际支付金额    收货地址               订单创建时间               订单付款时间  \\\n",
       "0     1  178.8       0.0     上海市  2022-03-21 00:00:00                  NaN   \n",
       "1     2   21.0      21.0  内蒙古自治区  2022-03-20 23:59:54  2022-03-21 00:00:02   \n",
       "2     3   37.0       0.0     安徽省  2022-03-20 23:59:35                  NaN   \n",
       "3     4  157.0     157.0     湖南省  2022-03-20 23:58:34  2022-03-20 23:58:44   \n",
       "4     5   64.8       0.0     江苏省  2022-03-20 23:57:04  2022-03-20 23:57:11   \n",
       "\n",
       "   退款金额  \n",
       "0   0.0  \n",
       "1   0.0  \n",
       "2   0.0  \n",
       "3   0.0  \n",
       "4  64.8  "
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 28010 entries, 0 to 28009\n",
      "Data columns (total 7 columns):\n",
      " #   Column    Non-Null Count  Dtype  \n",
      "---  ------    --------------  -----  \n",
      " 0   订单编号      28010 non-null  int64  \n",
      " 1   总金额       28010 non-null  float64\n",
      " 2   买家实际支付金额  28010 non-null  float64\n",
      " 3   收货地址      28010 non-null  object \n",
      " 4   订单创建时间    28010 non-null  object \n",
      " 5   订单付款时间    24087 non-null  object \n",
      " 6   退款金额      28010 non-null  float64\n",
      "dtypes: float64(3), int64(1), object(3)\n",
      "memory usage: 1.5+ MB\n"
     ]
    }
   ],
   "source": [
    "data.info()\n",
    "\n",
    "# 订单创建时间和订单付款时间 先修改成时间类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.订单创建时间 = pd.to_datetime(data.订单创建时间)\n",
    "data.订单付款时间 = pd.to_datetime(data.订单付款时间)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 28010 entries, 0 to 28009\n",
      "Data columns (total 7 columns):\n",
      " #   Column    Non-Null Count  Dtype         \n",
      "---  ------    --------------  -----         \n",
      " 0   订单编号      28010 non-null  int64         \n",
      " 1   总金额       28010 non-null  float64       \n",
      " 2   买家实际支付金额  28010 non-null  float64       \n",
      " 3   收货地址      28010 non-null  object        \n",
      " 4   订单创建时间    28010 non-null  datetime64[ns]\n",
      " 5   订单付款时间    24087 non-null  datetime64[ns]\n",
      " 6   退款金额      28010 non-null  float64       \n",
      "dtypes: datetime64[ns](2), float64(3), int64(1), object(1)\n",
      "memory usage: 1.5+ MB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 每天订单量统计可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       2022-03-21 00:00:00\n",
       "1       2022-03-20 23:59:54\n",
       "2       2022-03-20 23:59:35\n",
       "3       2022-03-20 23:58:34\n",
       "4       2022-03-20 23:57:04\n",
       "                ...        \n",
       "28005   2022-03-27 00:01:00\n",
       "28006   2022-03-27 00:00:18\n",
       "28007   2022-03-27 00:00:17\n",
       "28008   2022-03-27 00:00:09\n",
       "28009   2022-03-27 00:00:06\n",
       "Name: 订单创建时间, Length: 28010, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.订单创建时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "order_add_time = data.订单创建时间.map(lambda x: x.strftime('%Y-%m-%d'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        2022-03-21\n",
       "1        2022-03-20\n",
       "2        2022-03-20\n",
       "3        2022-03-20\n",
       "4        2022-03-20\n",
       "            ...    \n",
       "28005    2022-03-27\n",
       "28006    2022-03-27\n",
       "28007    2022-03-27\n",
       "28008    2022-03-27\n",
       "28009    2022-03-27\n",
       "Name: 订单创建时间, Length: 28010, dtype: object"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_add_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022-03-01': 176,\n",
       " '2022-03-02': 222,\n",
       " '2022-03-03': 267,\n",
       " '2022-03-04': 469,\n",
       " '2022-03-05': 369,\n",
       " '2022-03-06': 144,\n",
       " '2022-03-07': 177,\n",
       " '2022-03-09': 404,\n",
       " '2022-03-10': 27,\n",
       " '2022-03-11': 15,\n",
       " '2022-03-12': 1,\n",
       " '2022-03-13': 5,\n",
       " '2022-03-14': 7,\n",
       " '2022-03-15': 5,\n",
       " '2022-03-17': 390,\n",
       " '2022-03-18': 1015,\n",
       " '2022-03-19': 1025,\n",
       " '2022-03-20': 1345,\n",
       " '2022-03-21': 2068,\n",
       " '2022-03-22': 2027,\n",
       " '2022-03-23': 2200,\n",
       " '2022-03-24': 1998,\n",
       " '2022-03-25': 3416,\n",
       " '2022-03-26': 2849,\n",
       " '2022-03-27': 2586,\n",
       " '2022-03-28': 2691,\n",
       " '2022-03-29': 2112}"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照订单创建时间 分组，得到每一天的订单量\n",
    "result3 = data.groupby(order_add_time).agg({'订单编号': 'count'}).to_dict()['订单编号']\n",
    "result3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['2022-03-01',\n",
       " '2022-03-02',\n",
       " '2022-03-03',\n",
       " '2022-03-04',\n",
       " '2022-03-05',\n",
       " '2022-03-06',\n",
       " '2022-03-07',\n",
       " '2022-03-09',\n",
       " '2022-03-10',\n",
       " '2022-03-11',\n",
       " '2022-03-12',\n",
       " '2022-03-13',\n",
       " '2022-03-14',\n",
       " '2022-03-15',\n",
       " '2022-03-17',\n",
       " '2022-03-18',\n",
       " '2022-03-19',\n",
       " '2022-03-20',\n",
       " '2022-03-21',\n",
       " '2022-03-22',\n",
       " '2022-03-23',\n",
       " '2022-03-24',\n",
       " '2022-03-25',\n",
       " '2022-03-26',\n",
       " '2022-03-27',\n",
       " '2022-03-28',\n",
       " '2022-03-29']"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(result3.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"22c24df55d7644ba9d1db8dcd77f78df\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_22c24df55d7644ba9d1db8dcd77f78df = echarts.init(\n",
       "                    document.getElementById('22c24df55d7644ba9d1db8dcd77f78df'), 'white', {renderer: 'canvas'});\n",
       "                var option_22c24df55d7644ba9d1db8dcd77f78df = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8ba2\\u5355\\u91cf\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2022-03-01\",\n",
       "                    176\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-02\",\n",
       "                    222\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-03\",\n",
       "                    267\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-04\",\n",
       "                    469\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-05\",\n",
       "                    369\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-06\",\n",
       "                    144\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-07\",\n",
       "                    177\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-09\",\n",
       "                    404\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-10\",\n",
       "                    27\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-11\",\n",
       "                    15\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-12\",\n",
       "                    1\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-13\",\n",
       "                    5\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-14\",\n",
       "                    7\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-15\",\n",
       "                    5\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-17\",\n",
       "                    390\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-18\",\n",
       "                    1015\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-19\",\n",
       "                    1025\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-20\",\n",
       "                    1345\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-21\",\n",
       "                    2068\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-22\",\n",
       "                    2027\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-23\",\n",
       "                    2200\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-24\",\n",
       "                    1998\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-25\",\n",
       "                    3416\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-26\",\n",
       "                    2849\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-27\",\n",
       "                    2586\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-28\",\n",
       "                    2691\n",
       "                ],\n",
       "                [\n",
       "                    \"2022-03-29\",\n",
       "                    2112\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"type\": \"max\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0,\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u8ba2\\u5355\\u91cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u8ba2\\u5355\\u91cf\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2022-03-01\",\n",
       "                \"2022-03-02\",\n",
       "                \"2022-03-03\",\n",
       "                \"2022-03-04\",\n",
       "                \"2022-03-05\",\n",
       "                \"2022-03-06\",\n",
       "                \"2022-03-07\",\n",
       "                \"2022-03-09\",\n",
       "                \"2022-03-10\",\n",
       "                \"2022-03-11\",\n",
       "                \"2022-03-12\",\n",
       "                \"2022-03-13\",\n",
       "                \"2022-03-14\",\n",
       "                \"2022-03-15\",\n",
       "                \"2022-03-17\",\n",
       "                \"2022-03-18\",\n",
       "                \"2022-03-19\",\n",
       "                \"2022-03-20\",\n",
       "                \"2022-03-21\",\n",
       "                \"2022-03-22\",\n",
       "                \"2022-03-23\",\n",
       "                \"2022-03-24\",\n",
       "                \"2022-03-25\",\n",
       "                \"2022-03-26\",\n",
       "                \"2022-03-27\",\n",
       "                \"2022-03-28\",\n",
       "                \"2022-03-29\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6bcf\\u5929\\u8ba2\\u5355\\u91cf\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_22c24df55d7644ba9d1db8dcd77f78df.setOption(option_22c24df55d7644ba9d1db8dcd77f78df);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1e12a21bb20>"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Line()\n",
    "    .add_xaxis(list(result3.keys()))\n",
    "    .add_yaxis(\n",
    "        '订单量',\n",
    "        list(result3.values())\n",
    "    )\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "        markpoint_opts=opts.MarkPointOpts(\n",
    "            data=[\n",
    "                opts.MarkPointItem(type_='max')\n",
    "            ]\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='每天订单量')\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 每小时订单量统计可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "order_add_time2 = data.订单创建时间.map(lambda x: x.strftime('%H'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21    2204\n",
       "22    2126\n",
       "20    1990\n",
       "15    1720\n",
       "10    1672\n",
       "23    1644\n",
       "11    1640\n",
       "19    1532\n",
       "14    1500\n",
       "16    1481\n",
       "12    1367\n",
       "13    1339\n",
       "09    1283\n",
       "18    1270\n",
       "17    1205\n",
       "00    1043\n",
       "08     880\n",
       "07     556\n",
       "01     530\n",
       "02     341\n",
       "06     250\n",
       "03     189\n",
       "04     135\n",
       "05     113\n",
       "Name: 订单创建时间, dtype: int64"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_add_time2.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'00': 1043,\n",
       " '01': 530,\n",
       " '02': 341,\n",
       " '03': 189,\n",
       " '04': 135,\n",
       " '05': 113,\n",
       " '06': 250,\n",
       " '07': 556,\n",
       " '08': 880,\n",
       " '09': 1283,\n",
       " '10': 1672,\n",
       " '11': 1640,\n",
       " '12': 1367,\n",
       " '13': 1339,\n",
       " '14': 1500,\n",
       " '15': 1720,\n",
       " '16': 1481,\n",
       " '17': 1205,\n",
       " '18': 1270,\n",
       " '19': 1532,\n",
       " '20': 1990,\n",
       " '21': 2204,\n",
       " '22': 2126,\n",
       " '23': 1644}"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result4 = data.groupby(order_add_time2).agg({'订单编号': 'count'}).to_dict()['订单编号']\n",
    "result4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"4d9d582995894fcbadd4cbdeddcde68e\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_4d9d582995894fcbadd4cbdeddcde68e = echarts.init(\n",
       "                    document.getElementById('4d9d582995894fcbadd4cbdeddcde68e'), 'white', {renderer: 'canvas'});\n",
       "                var option_4d9d582995894fcbadd4cbdeddcde68e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u8ba2\\u5355\\u91cf\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                1043,\n",
       "                530,\n",
       "                341,\n",
       "                189,\n",
       "                135,\n",
       "                113,\n",
       "                250,\n",
       "                556,\n",
       "                880,\n",
       "                1283,\n",
       "                1672,\n",
       "                1640,\n",
       "                1367,\n",
       "                1339,\n",
       "                1500,\n",
       "                1720,\n",
       "                1481,\n",
       "                1205,\n",
       "                1270,\n",
       "                1532,\n",
       "                1990,\n",
       "                2204,\n",
       "                2126,\n",
       "                1644\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"type\": \"max\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u8ba2\\u5355\\u91cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u8ba2\\u5355\\u91cf\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"00\",\n",
       "                \"01\",\n",
       "                \"02\",\n",
       "                \"03\",\n",
       "                \"04\",\n",
       "                \"05\",\n",
       "                \"06\",\n",
       "                \"07\",\n",
       "                \"08\",\n",
       "                \"09\",\n",
       "                \"10\",\n",
       "                \"11\",\n",
       "                \"12\",\n",
       "                \"13\",\n",
       "                \"14\",\n",
       "                \"15\",\n",
       "                \"16\",\n",
       "                \"17\",\n",
       "                \"18\",\n",
       "                \"19\",\n",
       "                \"20\",\n",
       "                \"21\",\n",
       "                \"22\",\n",
       "                \"23\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6bcf\\u5c0f\\u65f6\\u8ba2\\u5355\\u91cf\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_4d9d582995894fcbadd4cbdeddcde68e.setOption(option_4d9d582995894fcbadd4cbdeddcde68e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1e12a4411c0>"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis( list(result4.keys()) )\n",
    "    .add_yaxis('订单量', list(result4.values()))\n",
    "    \n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "        markpoint_opts=opts.MarkPointOpts(\n",
    "            data=[\n",
    "                opts.MarkPointItem(type_='max')\n",
    "            ]\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='每小时订单量')\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
